﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RPGXEngine.Networking
{
    public class ClientDestinationInfomation : INetworkMessageObject
    {
        #region Enums

        public enum DestinationTypes
        {
            Client,
            Team,
            AllClients,
            Server,
        }

        #endregion

        #region Properties

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        private int _id = 0;

        public DestinationTypes DestinationType
        {
            get { return _destinationType; }
            set { _destinationType = value; }
        }
        private DestinationTypes _destinationType = DestinationTypes.Client;

        #endregion

        #region Public Methods

        public int GetMessageSize()
        {
            int size = 0;

            size += sizeof(int); // Id
            size += sizeof(int); // DestinationType - this is casted to an int in the byte stream

            return size;
        }

        public byte[] GetMessageAsBytes()
        {
            List<byte> bytes = new List<byte>();

            bytes.AddRange(BitConverter.GetBytes(this.Id));
            bytes.AddRange(BitConverter.GetBytes((int)this.DestinationType));

            return bytes.ToArray();
        }

        public int FromBytes(byte[] bytes, int startIndex)
        {
            this.Id = BitConverter.ToInt32(bytes, startIndex);
            startIndex += sizeof(int);

            this.DestinationType = (DestinationTypes)BitConverter.ToInt32(bytes, startIndex);
            startIndex += sizeof(int);

            return startIndex;
        }

        #endregion
    }
}
